$(function () {
  initCapitalIncome = 1;
  initCapitalIncomeData();
});

//界面数据初始化
function initCapitalIncomeData() {
  //请求参数
  var obj = {
    budgetYear: fullYear,
    budgetMonth: fullMonth,
    dept: fullDepartment,
    status: 2,
    chartPage: "5010201",
  };
  //API
  ApiGet("getdata", obj, function (e) {
    var json = JSON.parse(e);
    var chartData = json.items[0].charts;

    // setPanelData(chartData[0].data[0]);
    // getMonPayComplete(chartData[1].data);
    // getchartFieldPay(chartData[2].data);
    // getDeptTopPay(chartData[3].data);
    // setPanelMoney(chartData[4].data);
    // getTypePayRate(chartData[4].data);
    // getWlTopPay(chartData[5].data);
  });
}

let tableHeight = 830;
// let tableHeight = $("body").height();
//表格内容
var userData = 2;
var unitId = 1;
var searchVal = "";
var page = 1;
let limit = 10;
let coloms = [
  [
    {
      field: "PROJECT_NAME",
      title: "单位名称",
      width: "408",
      templet: function (d) {
        return `<div class="name">
					<span class="blue">${d.PROJECT_NAME.slice(0, 1)}</span>
					<p class="componname">北京东方科技发展有限公司</p><p class="compontype">院内<p>
				</div>`;
      },
    },
    {
      field: "ZL_QUESTION",
      title: "到款时间",
      align: "left",
      sort: true,
      width: "296",
    },
    {
      field: "ZR_DW",
      title: "到款类型",
      width: "296",
      align: "left",
    },
    {
      field: "XG_DW",
      title: "到款金额（万元）",
      width: "296",
      fixed: "right",
      align: "right",
      templet: function (d) {
        return `<div class="money">
						<p>¥32,134</p>
						<span>现金 ¥30,000  . 票据 ¥2,134</span>
					</div>`;
      },
    },
  ],
];

layui.use("table", function () {
  let table = layui.table;
  table.render({
    elem: "#tableList",
    cols: coloms,
    data: [
      {
        LAY_TABLE_INDEX: 1,
        LOSS_MONEY: 111,
        PROJECT_NAME: "啊实打实的",
        XG_DW: "相关单位1",
        ZL_QUESTION: "07/22",
        ZR_DW: "票据，现金",
      },
      {
        LAY_TABLE_INDEX: 1,
        LOSS_MONEY: 111,
        PROJECT_NAME: "啊实打实的",
        XG_DW: "相关单位1",
        ZL_QUESTION: "07/22",
        ZR_DW: "票据，现金",
      },
      {
        LAY_TABLE_INDEX: 1,
        LOSS_MONEY: 111,
        PROJECT_NAME: "啊实打实的",
        XG_DW: "相关单位1",
        ZL_QUESTION: "07/22",
        ZR_DW: "票据，现金",
      },
      {
        LAY_TABLE_INDEX: 1,
        LOSS_MONEY: 111,
        PROJECT_NAME: "啊实打实的",
        XG_DW: "相关单位1",
        ZL_QUESTION: "07/22",
        ZR_DW: "票据，现金",
      },
    ], // 数据
    limit: limit, // 每页显示的条数
    height: tableHeight,
  });
});

layui.use("laypage", function () {
  let laypage = layui.laypage;
  laypage.render({
    elem: "laypage", //注意，这里的 page 是 ID，不用加 # 号
    count: 50, //数据总数，从服务端得到
    theme: "#E8F3FF",
    limit: limit, // 每页条数
    prev: "<em><</em>",
    next: "<em>></em>",
    layout: ["count", "prev", "page", "next", "limit", "skip"],
    jump: function (obj, first) {
      //首次不执行
      if (!first) {
        limit = obj.limit;
        numpage(obj.curr, obj.limit); // 分页点击传参
      }
    },
  });
});

////////////////////点击切换/////////////////
console.log("asd", $(".samething"));

$(".samething").click(function () {
  console.log("aaa");
  $(this).addClass("choosed").siblings().removeClass("choosed");
});

//////////////获取url参数///////////
var href = decodeURIComponent(window.location.href);
console.log(href);
console.log(href.split("?")[1]);
var hreff = href.split("?")[1];
var hrefff = hreff.split("=")[1];
console.log(hrefff);

if (hrefff == "全部") {
  $(".samething:first").addClass("choosed");
} else {
  if (hrefff == "院内") {
    var test = $(".samething").eq(1);
    test.addClass("choosed");
  } else {
    if (hrefff == "院外集团内") {
      var test1 = $(".samething").eq(2);
      test1.addClass("choosed");
    } else {
      if (hrefff == "集团外") {
        var test2 = $(".samething").eq(3);
        test2.addClass("choosed");
      }
    }
  }
}
